package com.yjhb.android.sbz.v2.activity

import androidx.viewpager.widget.ViewPager
import com.yjhb.android.sbz.R
import com.yjhb.android.sbz.activity.BaseActivity
import com.yjhb.android.sbz.v2.activity.rule.V2RulePromotionRewardActivity
import com.yjhb.android.sbz.v2.activity.rule.V2RuleUserRewardActivity
import com.yjhb.android.sbz.v2.fragment.lastrank.V2GameRewardLastRankFragment
import com.yjhb.android.sbz.v2.fragment.lastrank.V2MakeMoneyLastRankFragment
import com.yjhb.android.sbz.v2.fragment.lastrank.V2PromotionLastRankFragment
import com.jojo.android.zxlib.adapter.FragmentAdapter
import com.jojo.android.zxlib.base.BaseFragment
import com.jojo.android.zxlib.base.mvp.BasePresenter
import com.jojo.android.zxlib.tool.ZxActivityTool
import com.jojo.android.zxlib.view.tablayout.listener.OnTabSelectListener
import kotlinx.android.synthetic.main.activity_layout_last_issue_rank.*


/**
 *  创建者 zx
 *  创建时间 2021/4/26 15:21
 */
class LastIssueRankActivity : BaseActivity<BasePresenter<*, *>>() {
    private val fragments = mutableListOf<BaseFragment<*>>()
    private val v2PromotionLastRankFragment = V2PromotionLastRankFragment()
    private val v2MakeMoneyLastRankFragment = V2MakeMoneyLastRankFragment()
    private val v2GameRewardLastRankFragment = V2GameRewardLastRankFragment()
    private val titles = arrayOf("推广奖励", "赚钱奖励", "游戏奖励")

    override fun initPresenter() = null

    override fun getLayoutId() = R.layout.activity_layout_last_issue_rank

    override fun initUI() {
        segmentTabLayout.setTabData(titles)
        fragments.add(v2PromotionLastRankFragment)
        fragments.add(v2MakeMoneyLastRankFragment)
        fragments.add(v2GameRewardLastRankFragment)
        viewpager.adapter = FragmentAdapter(supportFragmentManager, fragments)
        viewpager.offscreenPageLimit = 2
    }

    override fun initData() {
        viewpager.setCurrentItem(intent.getIntExtra("type", 1) - 1, false)
    }

    override fun regEvent() {
        back.setOnClickListener { finish() }
        title_right_tv.setOnClickListener { }

        segmentTabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                viewpager?.setCurrentItem(position, true)
            }

            override fun onTabReselect(position: Int) {

            }
        })
        viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {

            }

            override fun onPageSelected(position: Int) {
                segmentTabLayout.currentTab = position
            }
        })

        title_right_tv.setOnClickListener {
            when (viewpager.currentItem) {
                0 -> ZxActivityTool.skipActivity(activity, V2RulePromotionRewardActivity::class.java)
                1 -> ZxActivityTool.skipActivity(activity, V2RuleUserRewardActivity::class.java)
                2 -> ZxActivityTool.skipActivity(activity, V2RuleUserRewardActivity::class.java)
            }

        }
    }
}